package view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import controller.SistemaTelefonia;

public class PlanesLista extends javax.swing.JFrame {
	private static final long serialVersionUID = 1L;	

	private JButton cerrarButton;
	private SistemaTelefonia sistema;
	private Vector<String> columnas = new Vector<String>();

	public PlanesLista() {
	}

	public PlanesLista(SistemaTelefonia s) {
		super();
		sistema = s;
		initGUI();		
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);

			columnas.add("Plan Id");	
			columnas.add("Nombre");
			columnas.add("Facturable");
			{
			Vector datos = sistema.getPlanes();			
			TableModel jTable1Model = new DefaultTableModel(datos, columnas);
			JTable jTable1 = new JTable();
			getContentPane().add(jTable1);
			getContentPane().add(jTable1.getTableHeader(), BorderLayout.NORTH);
			jTable1.setModel(jTable1Model);
			jTable1.setBounds(14, 14, 800, 400);
			jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			jTable1.setLocation(new java.awt.Point(0, 4));
			
			/*JTable table = new JTable(this.sistema.getPlanes(), this.columnas);
			table.setBounds(0, 0, 200, 100);*/
			getContentPane().add(jTable1);
			}
			{
				cerrarButton = new JButton();
				getContentPane().add(cerrarButton);
				cerrarButton.setText("Cerrar");
				cerrarButton.setBounds(680, 410, 93, 28);
				cerrarButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
					}
				});
			}
			pack();
			setTitle("Planes");
			setSize(800, 500);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
